<template>
	<view>
		<u-navbar :is-back="true" :title="navbar.title" :background="navbar.background">
		</u-navbar>
		<view class="u-page">
			<view class="wrap">
				<u-form label-width="150">
					<u-form-item :label="$t('system.user.oldPassword')">
						<u-input v-model="pwdForm.oldPassword" :type="type"   ></u-input>
					</u-form-item>
					<u-form-item :label="$t('system.user.password')">
						<u-input v-model="pwdForm.password" :type="type"  ></u-input>
					</u-form-item>
					<u-form-item :label="$t('system.user.passwordConf')">
						<u-input v-model="pwdForm.passwordConf" :type="type"  ></u-input>
					</u-form-item>
				</u-form>
				<u-button style="margin-top: 20rpx;" shape="circle" @click="confirmChange">{{ $t('system.submit') }}</u-button>
			</view>
		</view>
		<footerBar></footerBar>
	</view>
</template>

<script>
	import service from '../../service.js';
	import mInput from '../../components/m-input.vue';
	import request from "utils/request.js"
	export default {
		components: {
			mInput
		},
		data() {
			return {
				type: 'password',
				passwordIcon: true,
				border: true,
				navbar: {
					title: this.$t('system.changPwd'),
					background: {
						backgroundColor: '#001f3f',
						backgroundImage: 'linear-gradient(45deg, rgb(28, 187, 180), rgb(141, 198, 63))'
					}
				},
				pwdForm: {
					oldPassword: "",
					password: "",
					passwordConf: ""
				}
			}
		},
		methods: {
			findPassword() {
				/**
				 * 仅做示例
				 */
				if (this.email.length < 3 || !~this.email.indexOf('@')) {
					uni.showToast({
						icon: 'none',
						title: '邮箱地址不合法',
					});
					return;
				}
				uni.showToast({
					icon: 'none',
					title: '已发送重置邮件至注册邮箱，请注意查收。',
					duration: 3000
				});
			},
			async confirmChange() {
				if (this.pwdForm.password != this.pwdForm.passwordConf) {
					this.$message.error('两次密码不一致');
					return;
				}
				if (this.pwdForm.password.length < 6) {
					this.$message.error('密码至少六位');
					return;
				}
				let resp = await request({
					url: '/system/user/changePassword',
					method: 'post',
					data: this.pwdForm
				})
				this.$u.route({
					url: "/pages/login/login"
				})
			}
		}
	}
</script>

<style>
.wrap{
	padding: 20rpx;
}
</style>
